<?php
class Cl_UserGroup extends WdkClass 
{
	protected
		/******************************************************/
		//	원본 테이블 정보
		/******************************************************/
		$user_group_seq				= 0		,	//	그룹 키값
		$user_group_name			= ''	,	//	그룹명
		$user_group_qualified_point	= ''	,	//	충족 포인트
		$user_group_level			= 0	,		//	충족 포인트
		$user_group_icon			= '',		//	충족 포인트
		$user_group_memo			= ''	,	//	메모사항
		$user_group_insert_time		= 0		,	//	등록시간
		$user_group_del_flag		= 'F'	;	//	삭제여부
		/******************************************************/
		//	추가 정보
		/******************************************************/
	
	/**
	 * 	
	 */
	function __construct()
	{
		parent::__construct();
		self::getDbo();
	}
	
	/**
	 *	
	 */
	public function __init($data)
	{
		parent::__init($data);
		self::dformat();
	}
	
	/**
	 *	
	 */
	public function load($user_group_seq)
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoad($user_group_seq));
	}
	
	/**
	 *	
	 */
	public function dformat()
	{
	
	}
	
	/**
	 * 
	 */
	public function autoUpdate($log='')
	{
		if((int)$this->user_group_seq > 0)
		{
			$this->update($log);
		}
		else
		{
			$this->insert($log);
		}
	}
	
	/**
	 *	
	 */
	public function insert($log='Insert')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$this->user_group_insert_time	= time();
		$this->user_group_del_flag		= 'F';
		
		$data = array(	'user_group_name'			=>	$this->user_group_name,
						'user_group_qualified_point'=>	$this->user_group_qualified_point,
						'user_group_level'			=>	$this->user_group_level,
						'user_group_icon'			=>	$this->user_group_icon,
						'user_group_memo'			=>	$this->user_group_memo,
						'user_group_insert_time'	=>	$this->user_group_insert_time,
						'user_group_del_flag'		=>	$this->user_group_del_flag
					);
		$this->user_group_seq = $dbo->insert($data);
		/******************************************************/
		parent::setBackupData(array_keys($data));
		$this->backup($log);
		/******************************************************/
	}
	
	/**
	 * 
	 */
	public function update($log='update')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		if(parent::isUpdatable())
		{
			$data = array(	'user_group_name'			=>	$this->user_group_name,
							'user_group_qualified_point'=>	$this->user_group_qualified_point,
							'user_group_level'			=>	$this->user_group_level,
							'user_group_icon'			=>	$this->user_group_icon,
							'user_group_memo'			=>	$this->user_group_memo
						);
			$dbo->update($data, array("user_group_seq = ".$this->user_group_seq));
			/******************************************************/
			parent::setBackupData(array_keys($data));
			$this->backup($log);
			/******************************************************/
		}
	}
	
	/**
	 * 
	 */
	public function delete($log='delete')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$dbo->delete(array("user_group_seq = ".$this->user_group_seq));
		/******************************************************/
		parent::setBackupData();
		$this->backup($log);
		/******************************************************/
	}
	
	/**
	 *	
	 */
	private function backup($log='')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$dbo->log($this->user_group_seq, $log, $this->backup_data);
	}
	
	/**
	 * 
	 */
	public function getDbo()
	{
		return Wdk::model(substr(__CLASS__, 3));
	}
}